
<!DOCTYPE html>
<html lang="en" xmlns:th="http://thymeleaf.org">
<head>
    <th:block th:include="include :: header('用户信息')"/>
</head>
<body class="white-bg">
<div class="container-div">
    <div class="ibox-content">
        <form class="form-horizontal m" id="dicForm" autocomplete="off">
            <input type="hidden" id="id" name="id" th:value="${id}">
            <input type="hidden" id="parentId" name="parentId" th:value="${parentDict.id}">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">字典标签：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="dicName" id="dicName" data-rule="required">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">字典值：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="dicValue" id="dicValue">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">字典编码：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" th:value="${parentDict.dicCode}" name="dicCode" id="dicCode" data-rule="required" readonly="readonly">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">显示顺序：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="number" name="sortNum" value="1" id="sortNum" data-rule="required">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input id="remark" name="remark" class="form-control" type="text">
                </div>
            </div>
            <div class="footerbar">
                <div class="col-sm-12 col-sm-offset-3">
                    <button class="btn btn-primary" type="submit">
                        <i class="fa fa-check"></i>
                        保存
                    </button>
                    <button class="btn btn-danger" type="button" onclick="cancel()">
                        <i class="fa fa-reply-all"></i>关闭
                    </button>
                </div>
            </div>
        </form>

    </div>
</div>

<th:block th:include="include :: footer"/>
<!-- jquery-validate 表单树插件 -->
<script type="text/javascript" th:inline="javascript">
    $(function () {
        $('#dicForm').validator({
            stopOnError: false,
            timely: 2,
            theme: "yellow_right",
            valid: function (form) {
                //console.log(form);
                jutils.ajaxPost("/admin/sysdic/save",$(form).serialize(),function (res){
                    if(res.status){
                        cancel();
                    }
                });
            },
        });
        loadModel();
    });
    function loadModel(){
        let id=$('#id').val();
        if(jutils.emptyId(id)){
            return;
        }
        jutils.ajaxGet('/admin/sysdic/getmodel',{id:id},function(res){
            if(res.status){
                let model=res.data.model;
                $('#dicForm').initFormData(model);
            }
        });
    }


    function cancel(){
        jutils.closeDialog();
    }

</script>
</body>
</html>